package com.knife.blog.logic.impl;

import com.knife.blog.domain.BlogResource;
import com.knife.blog.logic.BlogResourceService;
import com.knife.web.tools.DbPageList;
import com.knife.web.tools.IPageList;

public class BlogResourceServiceImpl extends DAOSupportService implements BlogResourceService {

	private static BlogResourceServiceImpl blogResourceService = new BlogResourceServiceImpl();

	public static BlogResourceServiceImpl getInstance() {
		return blogResourceService;
	}

	public boolean addBlogResource(BlogResource resource) {
		return this.dao.save(resource);
	}

	public boolean delBlogResource(String cid) {
		return this.dao.del(getBlogResource(cid));
	}

	public int batchDelBlogResource(String[] cids) {
        int ret = 0;
        for (int i = 0; i < cids.length; i++) {
            if (this.dao.del(cids[i])) {
                ret++;
            }
        }
        return ret;
	}

	public boolean updateBlogResource(BlogResource resource) {
		return this.dao.update(resource);
	}

	public BlogResource getBlogResource(String cid) {
		return (BlogResource) dao.get(BlogResource.class, cid);
	}

	public IPageList queryBlogBlogResource() {
		String scope = "1=1";
		return queryBlogResource(scope, null, 0, -1);
	}

	public IPageList queryBlogResource(String username, int currentPage,int pageSize) {
		String scope = "1=1";
		java.util.Collection<Object> paras = new java.util.ArrayList<Object>();
		paras.add(username);
		return queryBlogResource(scope, paras, currentPage, pageSize);
	}

	public IPageList queryBlogResource(String scope,
			java.util.Collection<Object> paras, int currentPage, int pageSize) {
		String sql = "";
		if (paras != null) {
			sql = " and inputuser=?";
		}
		if (scope != null) {
			sql = scope + sql;
		}
		DbPageList pList = new DbPageList(BlogResource.class, sql, paras);
		pList.doList(currentPage, pageSize);
		return pList;
		// return null;
	}
}
